package cn.tedu.knows.portal.controller;


import cn.tedu.knows.portal.model.User;
import cn.tedu.knows.portal.service.IUserService;
import cn.tedu.knows.portal.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2021-07-23
 */
@RestController
// 类上编写@RequestMapping表示
// 当前类中所有的控制器方法的请求路径要添加这里指定的前缀
@RequestMapping("/v1/users")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/master")
    public List<User> getTeachers(){
        List<User> list=userService.getTeachers();
        return list;
    }

    @GetMapping("/me")
    public UserVo me(@AuthenticationPrincipal UserDetails user){
        UserVo userVo=userService.getCurrentUserVo(
                                        user.getUsername());
        return userVo;
    }



}
